package com.forever7776.life.core.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.forever7776.life.core.common.vo.TweetsVO;
import com.forever7776.life.core.common.vo.UserTweetsVO;
import com.forever7776.life.core.entity.Tweets;
import com.forever7776.life.core.mapper.TweetsMapper;
import com.forever7776.life.core.service.ITweetsService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 动弹表 服务实现类
 * </p>
 *
 * @author kz
 * @since 2018-02-11
 */
@Service
public class TweetsServiceImpl extends ServiceImpl<TweetsMapper, Tweets> implements ITweetsService {

    @Autowired
    private TweetsMapper tweetsMapper;

    /**
     * 查询动弹列表
     *
     * @param page
     * @param userId
     * @param statusList
     * @return
     */
    @Override
    public Page<Tweets> selectAll(Page<Tweets> page, String userId, List<Integer> statusList) {
        EntityWrapper<Tweets> ew = new EntityWrapper<>();
        if (StringUtils.isNotEmpty(userId)) {
            ew.eq("user_id", userId);
        }

        if (CollectionUtils.isNotEmpty(statusList)) {
            ew.in("status", statusList);
        }
        ew.orderBy("id", false);
        return selectPage(page, ew);
    }

    /**
     * 查看用户动弹列表
     *
     * @param page
     * @param userId
     * @return
     */
    @Override
    public Page<UserTweetsVO> selectUserTweets(Page<UserTweetsVO> page, String userId,String currentUserId) {
        List<UserTweetsVO> list = tweetsMapper.selectUserTweetsVO(page, userId,currentUserId);
        page.setRecords(list);
        return page;
    }

    /**
     * 首页查询动弹列表（状态为显示的）
     *
     * @return
     */
    @Override
    public Page<TweetsVO> selectShowList(String userId) {
        Page<TweetsVO> page = new Page<>();
        List<TweetsVO> list = tweetsMapper.selectShowList(userId);
        page.setRecords(list);
        return page;
    }

    /**
     * 根据动弹ID查询用户ID
     *
     * @param id
     * @return
     */
    @Override
    public String selectUserIdById(Integer id) {
        return tweetsMapper.selectUserIdById(id);
    }
}
